// 这里没有解决跨域问题，但可以通过后解决跨域问题在后端的Controller层使用@CrossOrigin
import request from '../utils/request'


export function getGoodsList(currentPage, pageSize) {
  return request({
    url: '/goods',
    method: 'get',
    params: {
      currentPage,
      pageSize
    }
  })
}

export function getGoodListNum(currentPage, pageSize) {
  return request({
    url: '/goods/num',
    method: 'get',
    params: {
      currentPage,
      pageSize
    }
  })
}

export function getGoodListNumAndSale(currentPage, pageSize) {
  return request({
    url: '/goods/numAndSale',
    method: 'get',
    params: {
      currentPage,
      pageSize
    }
  })
}

export function getGoodsListFactoryNum(factoryId,currentPage, pageSize) {
  return request({
    url: '/goods/factoryNum',
    method: 'get',
    params: {
      factoryId,
      currentPage,
      pageSize
    }
  })
}

export function addGoods(goods, username) {
  return request({
    url: '/goods/add',
    method: 'post',
    params: {
      goods_id: '1',
      factory_id: goods.factory_id,
      goodsName: goods.goodsName,
      inside_id: goods.inside_id,
      now_price: 0,
      sale: goods.sale,
      stock: goods.num,
      type_name: goods.type_name,
      unit_price: goods.unit_price,
      username: username
    }
  })
}

export function deleteGoods(goods_id) {
  return request({
    url: '/goods/delete',
    method: 'post',
    params: {
      goods_id: goods_id
    }
  })
}

export function editGoods(goods) {
  return request({
    url: '/goods',
    method: 'put',
    data: {
      goodsId: goods.goodsId,
      igId:goods.igId,
      insideId:goods.insideId,
      goodsName: goods.goodsName,
      typeName: goods.typeName,
      unitPrice: goods.unitPrice,
      stock: goods.stock,
      factoryId: goods.factory.factoryId,
      sale: goods.sale,
      nowPrice: goods.nowPrice
    }
  })
}

export function findIsExist(inside_id, factory_id, username) {
  return request({
    url: '/goods/isExist',
    method: 'post',
    params: {
      inside_id: inside_id,
      factory_id: factory_id,
      username: username
    }
  })
}


export function findGoods(flag, value, currentPage, pageSize) {
    return request({
      url: '/goods/find',
      method: 'get',
      params: {
        flag,
        value,
        currentPage,
        pageSize
      }
    })
}

export function  exportExcel(){
  return request({
    url: '/goods/export',
    method: 'get',
    responseType: 'blob'
  })
}
